<?php
namespace app\admin\controller;

use app\BaseController;
use app\common\model\Menu as MenuModel;
use app\common\model\Config as ConfigModel;
/**
 * 后台基础控制器
 */
class Admin extends BaseController
{
	/**
     * 控制器初始化
     */
    protected function initialize(){
    	// 判断是否登录，并定义用户ID常量
        defined('UID') or define('UID', is_login());
        if(!UID){
            $this->redirect((string)url('Login/index'));
        }
        /*读取数据库中的配置*/
        $config = cache('db_config_data');
        if(!$config){
            $config = ConfigModel::lists();            
            cache('db_config_data', $config);
        }
        config($config, 'app'); //添加配置

        if (!$this->request->isAjax()) {
            $menu['main'] = MenuModel::getTopmenu();
            $menu['operater'] = MenuModel::getSubmenu();            
            $path = MenuModel::getPath();
            
            $this->assign('__MENU__',$menu);
            $this->assign('path',$path);       
        }
    }    
}